/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.chat;

import chat.ChatMessage;
import chat.TextChatMessage;
import java.util.*;
import javax.swing.AbstractListModel;

/**
 *
 * @author salm
 */
public class ChatMessageModel extends AbstractListModel
{
    private List<TextChatMessage> messages;
    
    public ChatMessageModel()
    {
        this.messages = new LinkedList();
    }
    
    public ChatMessageModel(Collection<TextChatMessage> msgs)
    {
        this.messages = new LinkedList(msgs);
    }
    
    @Override
    public int getSize()
    {
        return this.messages.size();
    }

    @Override
    public Object getElementAt(int index)
    {
        return this.messages.get(index);
    }
    
    public void addMessage(TextChatMessage msg)
    {
        this.messages.add(msg);
        this.fireIntervalAdded(this, this.messages.size() - 1, this.messages.size());
    }
}